import { defineStore } from 'pinia';
import { USER_TOKEN } from '@/constants/local-storage-key-const';
import { userApi } from '@/http/userApi.js';

const defaultUserInfo = {
  id:'',
  headimgurl:'',
  mobile:'',
  userName:'',
  wxName:'',
  loginStatus:false,
  statusBarHeight:10,
  titleBarWidth:0,
  titleBarHeight:40,
  menuButtonHeight:32,
};

export const useUserStore = defineStore({
  id: 'userStore',
  state: () => ({
    ...defaultUserInfo,
  }),
  getters: {
    getToken(state) {
      return uni.getStorageSync(USER_TOKEN);
    },
  },

  actions: {
	setStatusBarHeight(statusBarHeight){
		this.statusBarHeight = statusBarHeight
	},
	setWxHeader(wxHeader){
		this.statusBarHeight = wxHeader.statusBarHeight
	  	this.menuButtonHeight = wxHeader.menuButtonHeight
	  	this.titleBarWidth = wxHeader.titleBarWidth
	  	this.titleBarHeight = wxHeader.titleBarHeight
	},
    logout() {
      this.token = null;
      uni.removeStorage(USER_TOKEN);
    },
    clearUserLoginInfo() {
      this.setUserLoginInfo(defaultUserInfo);
      uni.removeStorage(USER_TOKEN);
    },
    async getLoginInfo() {
      // let res = await loginApi.getLoginInfo();
      // this.setUserLoginInfo(res.data);
    },
    //设置登录信息
    setUserLoginInfo(data) {
		this.id = data.id
		this.loginStatus = true
		this.headimgurl = data.headimgurl
		this.mobile = data.mobile
		this.userName = data.userName
		this.wxName = data.wxName

      // uni.setStorageSync(USER_TOKEN, data.token);
    },
  },
});
